package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.security.utils.SecurityUtils;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.OaKeyworkDailyQuery;
import com.jcfk.system.domain.dto.OaKeyworkDailyDTO;
import com.jcfk.system.domain.dto.OaKeyworkDailyDetailDTO;
import com.jcfk.system.service.OaKeyworkDailyService;

import java.util.List;

/**
 * 日报计划事项
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-04-01
 */
@Api(tags = {"日报计划事项管理"})
@RestController
@RequestMapping("oakeyworkdaily")
public class OaKeyworkDailyController {
    @Autowired
    private OaKeyworkDailyService oaKeyworkDailyService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<OaKeyworkDailyQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询日报计划事项")
    @PostMapping("/queryByPage")
    public RetPage<OaKeyworkDailyDTO> queryByPage(@RequestBody ReqPageParam<OaKeyworkDailyQuery> requestParam) {
        DataPage<OaKeyworkDailyDTO> page = new DataPage<OaKeyworkDailyDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            OaKeyworkDailyDTO.class);
        requestParam.getData().setCreatedUserId(SecurityUtils.getUserId());
        page = oaKeyworkDailyService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<OaKeyworkDailyQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询日报计划事项")
    @PostMapping("/queryAllByPage")
    public RetPage<OaKeyworkDailyDTO> queryAllByPage(@RequestBody ReqPageParam<OaKeyworkDailyQuery> requestParam) {
        DataPage<OaKeyworkDailyDTO> page = new DataPage<OaKeyworkDailyDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
                OaKeyworkDailyDTO.class);
        page = oaKeyworkDailyService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }



    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "OaKeyworkDailyQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取日报计划事项列表", notes = "获取日报计划事项列表", httpMethod = "POST")
    @PostMapping("getDetails")
    public RetResult<List<OaKeyworkDailyDetailDTO>> getDetails(@RequestBody OaKeyworkDailyQuery query) {

        List<OaKeyworkDailyDetailDTO> list = oaKeyworkDailyService.getDetails(query);

        return RetResult.ok(list);
    }

    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "OaKeyworkDailyQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取日报计划事项列表", notes = "获取日报计划事项列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<OaKeyworkDailyDTO>> getList(@RequestBody OaKeyworkDailyQuery query) {

        List<OaKeyworkDailyDTO> list = oaKeyworkDailyService.getList(query);

        return RetResult.ok(list);
    }


    /**
     *  日报计划事项
     * 根据id 查询详情
     */
    @ApiOperation("查询日报计划事项")
    @GetMapping("/get/{id}")
    public RetResult<OaKeyworkDailyDTO> get(@PathVariable("id") String id) {
            OaKeyworkDailyDTO item = oaKeyworkDailyService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理日报计划事项
     */
    @ApiOperation("保存日报计划事项")
    @PostMapping("/save")
    @RequestLogHeader(modular = "日报计划事项管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid OaKeyworkDailyDTO oaKeyworkDaily) {
        // 数据校验
        RetResult ret = oaKeyworkDailyService.isValid(oaKeyworkDaily);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(oaKeyworkDaily.getId())){
            // 新增
                oaKeyworkDailyService.insert(oaKeyworkDaily);
        } else{
            // 更新
                oaKeyworkDailyService.update(oaKeyworkDaily);
        }
        return RetResult.ok();

    }


    /**
     *  批量删除日报计划事项
     */
    @ApiOperation("批量删除日报计划事项")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "日报计划事项管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody OaKeyworkDailyDTO oaKeyworkDaily) {
        return RetResult.ok(oaKeyworkDailyService.logicDeleteList(oaKeyworkDaily));
    }

}
